package ui;

import java.util.Vector;

import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import simulationEngine.SimulationEngine;
import ui.grafic.Grafics;
import ui.grafic.RosterExecutionGrafic;
import datatypes.HostDescription;
import datatypes.ScenarioDescription;

public class SimulationExecutionRosterCard extends JScrollPane {

	private JSplitPane contentContainer = null;
	//left Component == Stack
	private JList leftComponent = null;
	//right Component == Grafics
	private RosterExecutionGrafic rightComponent = null;
	
	private Vector<String> stackContent = null;
	
	public SimulationExecutionRosterCard (SimulationEngine engine){
		super();
		this.stackContent = engine.getScenarioParameter().getSimpleActionNames();
		this.setViewportView(this.getContentContainer(engine));
	}
	
	private JSplitPane getContentContainer(SimulationEngine engine){
		if (contentContainer == null){
			contentContainer = new JSplitPane();
			contentContainer.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
			contentContainer.setLeftComponent(new JScrollPane(this.getLeftComponent()));
			contentContainer.setRightComponent(this.getRightComponent(engine.getScenarioParameter()));
			contentContainer.setDividerLocation(120);
		}
		return contentContainer;
	}
	
	private JList getLeftComponent(){
		if (leftComponent== null){
			leftComponent = new JList(stackContent);
		}
		return leftComponent;
	}
	
	private RosterExecutionGrafic getRightComponent(ScenarioDescription desc){
		if (rightComponent == null){
			rightComponent = new RosterExecutionGrafic(desc.getRosterWidth(), desc.getRosterHeight(), desc.getRange());
			rightComponent.buildGrafic(desc.getHosts());
		}
		return rightComponent;
	}
}
